package uba.ing2.subite.services;

import uba.ing2.subite.services.authorizationrules.PaymentAuthorizationRule;

/**
 * Representa el resultado autorizado o rechazado de un a {@link PaymentAuthorizationRule regla de autorización}.
 */
public class PaymentAuthorizationResult {	
	private static final PaymentAuthorizationResult AUTHORIZED = new PaymentAuthorizationResult("");
	private final String rejectionReason;

	/**
	 * Crea un resultado de autorización según el valor boolean dado.
	 * @return un resultado autorizado si la condición es <i>true</i> o uno rechazado con la razón dada
	 * si la condición es <i>false</i>.
	 */
	public static PaymentAuthorizationResult createFromCondition(boolean condition, String rejectionReason) {
		return (condition) ? autorized() : rejected(rejectionReason);
	}

	/**
	 * Retorna un resultado de "pago autorizado".
	 */
	public static PaymentAuthorizationResult autorized() {
		return AUTHORIZED;
	}
	
	public static PaymentAuthorizationResult rejected(String reason) {
		return new PaymentAuthorizationResult(reason);
	}
	
	public PaymentAuthorizationResult(String rejectionReason) {
		this.rejectionReason = rejectionReason;
	}

    public boolean isAuthorized() {
    	return this == AUTHORIZED;
    }
    
    public String rejectionReason() {
    	return rejectionReason;
    }
}
